﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace Pc_Vision.View_Datalayer
{
    public partial class viewActieEdit : System.Web.UI.Page
    {

        protected override void OnInit(EventArgs e)
        {


        }

        public void fn_Cancel(object sender, EventArgs e)
        {
            //hoi
            Response.Redirect("Index.aspx");
        }

        public void fn_SaveActie(object sender, EventArgs e)
        {
            DAOFactorys.DAOactie daoActie = new DAOFactorys.DAOactie();
            Model.Actie a = new Model.Actie();
            a.actieNaam = tbActionName.Text;
            a.startTijd = tbStartDate.Text;
            a.eindTijd = tbEndDate.Text;
            daoActie.UpdateActie(a);


        }
/*

        public void fn_SearchCategorie(object sender, EventArgs e)
        {
            DAOFactorys.DAOcategorie daoCategorie = new DAOFactorys.DAOcategorie();
            ArrayList arr = daoCategorie.GetAllCategories();
            string searchval = tbCategorieName.Text;
            foreach (Model.Categorie obj in arr)
            {
                if (obj.categorieName == searchval)
                {
                    tbCategorieDescription.Text = obj.categorieDescription;
                    tbCategorieId.Text = obj.id;

                }
            }
        }

        */

        public void fn_SearchActie(object sender, EventArgs e)
        {
            DAOFactorys.DAOactie daoActie = new DAOFactorys.DAOactie();
            ArrayList arr = daoActie.GetAllActies();
           // string searchVal = tbActionName.Text;

            foreach(Model.Actie obj in arr)
            {
                string searchVal = tbActionName.Text;
                if (obj.actieNaam == searchVal)
                {
                    tbActionName.Text = obj.actieNaam;
                    tbStartDate.Text = obj.startTijd;
                    tbEndDate.Text = obj.eindTijd;
                

                }
            }

        }
        /*    base.OnInit(e);

            if (Request.QueryString["actieid"] == null)
            {
                DetailsView1.DefaultMode = DetailsViewMode.Insert;
            }
            else
            {
                DetailsView1.DefaultMode = DetailsViewMode.Edit;
            }
            this.Page.Title = "Editing record";
        }

        protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
            }
            else if (e.CommandName == "Insert")
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true);
            }
        }

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            //logic to truncate long string to prevent SQL error
            for (int i = 1; i < 4; i++)
            {
                string val = e.NewValues[i - 1].ToString();
                int maxLength = i * 10;
                if (val.Length > maxLength) e.NewValues[i - 1] = val.Substring(0, maxLength);
            }
        }
        */
    }
    
}